import type { SortParam } from '@/api/types/SortParam.ts'
import { httpClient } from '@/config'


export function siteList(groupId: string) {
    return httpClient.send<Array<Site>>({
        url: '/site/' + groupId,
        method: 'GET',
    })
}

export function createSite(data: SiteParam) {
    return httpClient.send<string>({
        url: '/site',
        method: 'POST',
        data,
    })
}

export function updateSite(data: SiteParam) {
    return httpClient.send<string>({
        url: '/site',
        method: 'PUT',
        data,
    })
}

export function updateSiteSort(data: Array<SortParam>) {
    return httpClient.send<string>({
        url: '/site/sort',
        method: 'PUT',
        data,
    })
}

export function removeSite(siteId: string) {
    return httpClient.send<void>({
        url: '/site/' + siteId,
        method: 'DELETE',
    })
}

export function removeSiteList(siteIds: Array<string>) {
    return httpClient.send<void>({
        url: '/site',
        method: 'DELETE',
        params: {
            id: siteIds,
        },
    })
}


/**
 * Site
 */
export interface Site {
    /**
     * 账户ID
     */
    accountId?: number;

    /**
     * 描述信息, 可空 非 null
     */
    description: string;

    /**
     * 图标
     */
    icon: string;

    /**
     * ID
     */
    id: string | null;

    /**
     * 名字
     */
    name: string;

    /**
     * 排序
     */
    sort: number;

    /**
     * 网址
     */
    url: string;

    /**
     * 版本
     */
    version?: number;

}

export interface SiteParam extends Site {
    /**
     * 所属分组
     */
    groupId: string
}
